var pwStrength = function (pwd) {//显示颜色
  var msg
  if (!pwd.trim()) {
    // Lcolor = Mcolor = Hcolor = O_color;
  } else {
    var S_level = checkStrong(pwd);
    switch (S_level) {
      case 0:
        break
      case 1:
        msg = '密码不能使用纯数字,纯字母或纯符号'
        break
      case 2:
        break
      default:
    }
  }
  if (msg) {
    return 1
  }
}

//判断输入密码的类型
function CharMode(iN) {
  if (iN >= 48 && iN <= 57) {//数字
    return 1
  } else if (iN >= 65 && iN <= 90) {//大写
    return 2
  } else if (iN >= 97 && iN <= 122) {//小写
    return 4
  } else {
    return 8
  }
}

//bitTotal函数
//计算密码模式
function bitTotal(num) {
  switch (num) {
    case 6:
      num = 1;
      break;
    case 14:
      num = 5;
      break;
    case 7:
      num = 5;
      break;
    default:
      break
  }
  var modes = 0;
  for (var i = 0; i < 4; i++) {
    if (num & 1) {
      modes++
    }
    num >>>= 1;
  }
  return modes;
}

//返回强度级别
function checkStrong(sPW) {
  if (sPW.length < 8) {//密码太短
    return 0
  } else {
    var Modes = 0;
    for (var i = 0; i < sPW.length; i++) {
      Modes = Modes | CharMode(sPW.charCodeAt(i));//密码模式
    }
    return bitTotal(Modes);
  }
}
module.exports = {
  pwStrength: pwStrength
}